package servlet.ware;

import java.io.IOException;
import java.net.URLEncoder;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.Page;
import service.GoodsService;

/**
 * Servlet implementation class goods_search_Servlet
 */
@WebServlet("/goods_search")
public class ware_search_Servlet extends HttpServlet {

	private  GoodsService  gService  = new GoodsService();
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String keyword = request.getParameter("keyword");
		
		int	pageNo  = 1;
		if(request.getParameter("pageNo") != null) {
			
			pageNo = Integer.parseInt(request.getParameter("pageNo"));
			
		}
		
		Page  p = gService.getSearchGoodsPage(keyword,pageNo);
		request.setAttribute("p", p);
		request.setAttribute("keyword", URLEncoder.encode(keyword,"UTF-8"));  // 进行编码的转换
		request.getRequestDispatcher("/ware_search.jsp").forward(request, response);
		
	}


}
